#ifndef XMLSAXPARSER_HPP
# define XMLSAXPARSER_HPP

# include <QXmlDefaultHandler>
# include <map>
# include "Scene.hpp"
# include "3D/Model.hpp"
# include "3D/Texture.hpp"

class XmlSaxParser: public QXmlDefaultHandler
{
public:
    XmlSaxParser();

    void    prepareReading();
    Scene*  readFile(QString const& fileName);

protected:
    bool    startElement(const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &attributes);
    bool    endElement(const QString &namespaceURI, const QString &localName, const QString &qName);
    bool    characters(const QString &str);
    bool    fatalError(const QXmlParseException &exception);

private:
    Scene*                          _builtScene;
    Terrain*                        _builtTerrain;
    DrawableObject*                 _builtTerrainDrawable;
    unsigned int                    _builtVertex;
    unsigned int                    _builtIndex;
    VertexAttributes*               _builtVertices;
    unsigned int*                   _builtIndexes;
    Model*                          _builtModel;
    Texture*                        _builtTexture;

    typedef void (XmlSaxParser::*LoaderMember)(QString const&);
    std::map<std::string, LoaderMember> _filler;
    LoaderMember                    _nextCalledMethod;

    void    fillScene(QString const& data);
    void    fillName(QString const& data);
    void	fillWidth(QString const& data);
    void	fillHeight(QString const& data);
    void	fillTerrain(QString const& data);
    void	fillNbVertices(QString const& data);
    void	fillNbIndexes(QString const& data);
    void	fillVertex(QString const& data);
    void	fillPosX(QString const& data);
    void	fillPosY(QString const& data);
    void	fillPosZ(QString const& data);
    void	fillColR(QString const& data);
    void	fillColG(QString const& data);
    void	fillColB(QString const& data);
    void	fillNormX(QString const& data);
    void	fillNormY(QString const& data);
    void	fillNormZ(QString const& data);
    void	fillTextX(QString const& data);
    void	fillTextY(QString const& data);
    void	fillTextZ(QString const& data);
    void	fillIdX(QString const& data);
    void	fillIdY(QString const& data);
    void	fillIdZ(QString const& data);
    void	fillIndex(QString const& data);
    void	fillModel(QString const& data);
    void	fillModelPath(QString const& data);
    void	fillModelPosX(QString const& data);
    void	fillModelPosY(QString const& data);
    void	fillModelPosZ(QString const& data);
    void    fillTexture(QString const& data);
    void    fillTextName(QString const& data);
    void    fillTextPath(QString const& data);
    void    fillTextBehaviour(QString const& data);

};

#endif // XMLSAXPARSER_HPP
